﻿using System;
using System.Collections.Generic;
using System.Text;

namespace CanSWAT.SWAT
{
    class SnowRedistribution
    {
        public static string DEFAULT_HRU_PARAMETER_NAME  = "hru_sr.txt";
        public static string DEFAULT_PARAMETER_NAME = "snow.txt";
        public static string DEFAULT_SNOW_HOLDING_CAPACITY_NAME = "shc.txt";

        private string _foler = "";
        private SnowRedistributionParameterFile _parameter = null;
        private SWATFile _hruParameterFile = null;
        private SWATFile _shcFile = null;

        public SnowRedistribution(string folder)
        {
            if(!System.IO.Directory.Exists(folder)) return;
            _foler = System.IO.Path.GetFullPath(folder);

            _hruParameterFile = 
                new SWATFile(_foler + @"\" + DEFAULT_HRU_PARAMETER_NAME);
            _shcFile = 
                new SWATFile(_foler + @"\" + DEFAULT_SNOW_HOLDING_CAPACITY_NAME);
            _parameter = 
                new SnowRedistributionParameterFile(_foler + @"\" + DEFAULT_PARAMETER_NAME);          
        }

        public void Edit(SnowRedistributionFileType type)
        {
            SWATFile file = getFile(type);
            if (file != null) file.Edit();
            else CanSWAT.showInformationWindow("Something wroing with " + type.ToString());
        }

        public string getFileName(SnowRedistributionFileType type)
        {
            SWATFile file = getFile(type);
            if (file != null) return file.File;
            else 
                throw new System.Exception("Something wrong with " + type.ToString());            
        }

        private SWATFile getFile(SnowRedistributionFileType type)
        {
            switch (type)
            {
                case SnowRedistributionFileType.GeneralParameter:
                    return _parameter as SWATFile;
                case SnowRedistributionFileType.HRUParameter:
                    return _hruParameterFile;
                case SnowRedistributionFileType.SnowHoldingCapacityLookup:
                    return _shcFile;
            }
            return null;
        }
    }
}
